package com.market.manager.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.market.dao.PromotionDao;
import com.market.domain.Location;
import com.market.domain.Promotion;
import com.market.manager.PromotionManager;
@Service("promotionManager")
public class PromotionManagerImpl extends
		GenericManagerImpl<PromotionDao, Promotion, Long> implements
		PromotionManager {

	@Autowired
	public void setDao(PromotionDao promotionDao) {
		this.dao = promotionDao;
	}
	
	

	public List<Location> fetchLocations(Promotion promotion) {
		return this.dao.findLocations(promotion);
	}



	@Override
	public Promotion fetchOne(Long id) {
		Promotion promotion = super.fetchOne(id);
		promotion.setLocations(this.fetchLocations(promotion));
		return promotion;
	}



	public Promotion fetchOne(Promotion promotion) {
		return this.fetchOne(promotion.getId());
	}


	public List<Promotion> fetchValidPromotions(Date date, Long locationId) {
		return this.dao.findValidPromotions(date, locationId);
	}	

}
